package com.xiaohui.home.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xiaohui.feigin.service.SkuFeignService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Resource
    private RestTemplate restTemplate;

    private static final String URL = "http://127.0.0.1:8083/test";

    @Resource
    private SkuFeignService skuFeignService;


    @RequestMapping("/test")
    public String test() {
//        return restTemplate.getForObject(URL, String.class);
        return skuFeignService.test();
    }


    @GetMapping("/testHystrixTimeout")
    @HystrixCommand(fallbackMethod = "testHystrixTimeoutHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "500")
    })
    public String testHystrixTimeout() throws InterruptedException {
        return skuFeignService.testHystrixTimeout();
    }

    public String testHystrixTimeoutHandler() {
        return "调用方降级啦！！！";
    }

}
